package sicnu.cs.aps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import sicnu.cs.aps.domain.entity.StudentInfo;
import sicnu.cs.aps.domain.vo.SimpleUserDetailInfoVo;
import sicnu.cs.aps.mapper.StudentInfoMapper;
import sicnu.cs.aps.mapper.TeacherInfoMapper;
import sicnu.cs.aps.service.IStudentInfoService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author CaiKe
 * @date 2022/6/2 12:04
 */
@Service
@AllArgsConstructor
public class StudentInfoServiceImpl extends ServiceImpl<StudentInfoMapper, StudentInfo> implements IStudentInfoService {

    private final StudentInfoMapper studentInfoMapper;

    /**
     * 通过模糊条件查询学生信息(学号和姓名)
     *
     * @param condition 学号或姓名
     * @return 返回学号姓名的列表
     */
    @Override
    public List<SimpleUserDetailInfoVo> listStudentByCondition(String condition) {
        List<StudentInfo> studentInfos ;
        List<SimpleUserDetailInfoVo> list = new ArrayList<>();

        try {
            Long sid = Long.valueOf(condition);
            //查询学号
            studentInfos = studentInfoMapper.selectStByPrefixSid(condition);
        } catch (NumberFormatException e) {
            //查询姓名
            studentInfos = studentInfoMapper.selectStByPrefixName(condition);
        }
        studentInfos.forEach(studentInfo -> list.add(SimpleUserDetailInfoVo.builder().value(studentInfo.getName()).label(studentInfo.getUserId()).build()));
        System.out.println(1);
        return list;
    }


}